package chat.network.http;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;

import com.alibaba.fastjson.JSON;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;
import com.whu.administrator.ws.VolleySingleton;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import inter.Delegate;

/**
 * 添加好友
 * Created by 凯 on 2015/10/18.
 */
public class AddFriend {

    Delegate delegate;
    SubscripContact subscripContact;

    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    public void setSubscripContact(SubscripContact subscripContact) {
        this.subscripContact = subscripContact;
    }

    public void add()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url ="http://"+IP+"/Chat/AddContact";
        StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (delegate != null)
                            delegate.onResponse(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (delegate != null)
                    delegate.onErrorResponse(error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                Gson gson = new Gson();
                map.put("data",gson.toJson(subscripContact));
                return  map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data,"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }


    public static class SubscripContact {
        private String subscrip_from_ID;
        private String subscrip_to_ID;
        private String subscrip_from_Group;
        private String subscrip_Time;
        private String subscrip_Desc;


        public String getSubscrip_from_ID() {
            return subscrip_from_ID;
        }
        public void setSubscrip_from_ID(String subscrip_from_ID) {
            this.subscrip_from_ID = subscrip_from_ID;
        }
        public String getSubscrip_to_ID() {
            return subscrip_to_ID;
        }
        public void setSubscrip_to_ID(String subscrip_to_ID) {
            this.subscrip_to_ID = subscrip_to_ID;
        }
        public String getSubscrip_from_Group() {
            return subscrip_from_Group;
        }
        public void setSubscrip_from_Group(String subscrip_from_Group) {
            this.subscrip_from_Group = subscrip_from_Group;
        }
        public String getSubscrip_Time() {
            return subscrip_Time;
        }
        public void setSubscrip_Time(String subscrip_Time) {
            this.subscrip_Time = subscrip_Time;
        }
        public String getSubscrip_Desc() {
            return subscrip_Desc;
        }
        public void setSubscrip_Desc(String subscrip_Desc) {
            this.subscrip_Desc = subscrip_Desc;
        }
    }


    public static class AddContactStatus {
        public static final String FAILED = "0";
        public static final String SUCCESS = "1";
        public static final String BOTH = "2";
        public static final String FROM = "3";
        public static final String TO = "4";
    }

    public static class ResponseAddContact {
        private String status;

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }
    }
}
